﻿@using System.Globalization
@using Magicodes.Admin.Editions
@using Magicodes.Admin.MultiTenancy.Payments;
@model Magicodes.Admin.Web.Models.Payment.PaymentViewModel

@{
    Layout = "~/Views/Account/_Layout.cshtml";
    ViewBag.DisableTenantChange = true;
}

@section Scripts
{
    <environment names="Development">
        <script src="~/view-resources/Views/Payment/Payment.js" asp-append-version="true"></script>
    </environment>

    <environment names="Staging,Production">
        <script src="~/view-resources/Views/Payment/Payment.min.js" asp-append-version="true"></script>
    </environment>
}

<form class="register-form" method="post" asp-action="@Model.GetFormAction()" asp-controller="@Model.GetFormPostController()" asp-area="@Model.GetFormArea()" id="formPaymentResult">
    <input type="hidden" name="EditionId" value="@Model.Edition.Id" />
    <input type="hidden" name="Gateway" value="" />
    <input type="hidden" name="EditionPaymentType" value="@Model.EditionPaymentType" />
    <input type="hidden" name="SubscriptionStartType" value="@Model.SubscriptionStartType" />

    <h3>@L("PaymentInfo")</h3>
    @if (Model.EditionPaymentType == EditionPaymentType.Extend || Model.EditionPaymentType == EditionPaymentType.Upgrade)
    {
        <div class="hint text-center">(@L(Model.EditionPaymentType + "_Edition_Description", Model.Edition.DisplayName))</div>
    }
    else
    {
        <div class="hint text-center">(@Model.Edition.DisplayName @L("Edition"))</div>
    }

    @if (ViewBag.ErrorMessage != null)
    {
        <div class="alert alert-danger">
            <i class="fa fa-warning"></i> @ViewBag.ErrorMessage
        </div>
    }

    @if (Model.IsUpgrading())
    {
        <hr class="border-green" />
        <div class="form-actions">
            <div class="form-group row">
                <label class="col-sm-8 control-label">@L("Total")</label>
                <div class="col-sm-4 text-right">
                    <p class="form-control-static text-bold" id="totalPrice">
                        $@Model.AdditionalPrice.Value.ToString("N2")
                    </p>
                </div>
            </div>
        </div>
    }
    else
    {
        if (Model.Edition.MonthlyPrice.HasValue)
        {
            <div class="form-group">
                <label class="mt-radio mt-radio-outline margin-bottom-0">
                    <input class="form-control" type="radio" name="PaymentPeriodType"
                           data-day-count="@((int)PaymentPeriodType.Monthly)"
                           data-payment-period-type-amount="@(Model.Edition.MonthlyPrice.Value.ToString("0.00", CultureInfo.InvariantCulture))"
                           value="@PaymentPeriodType.Monthly" />@L("MonthlyPrice"): $@Model.Edition.MonthlyPrice.Value.ToString("N2")
                        <span></span>
                    </label>
                </div>
        }

        if (Model.Edition.AnnualPrice.HasValue)
        {
            <div class="form-group">
                <label class="mt-radio mt-radio-outline margin-bottom-0">
                    <input class="form-control" type="radio" name="PaymentPeriodType"
                           data-day-count="@((int)PaymentPeriodType.Annual)"
                           data-payment-period-type-amount="@(Model.Edition.AnnualPrice.Value.ToString("0.00", CultureInfo.InvariantCulture))"
                           value="@PaymentPeriodType.Annual" />@L("AnnualPrice"): $@Model.Edition.AnnualPrice.Value.ToString("N2")
                        <span></span>
                    </label>
                </div>
        }
    }

    @foreach (var paymentGatewayAdditionalData in Model.Edition.AdditionalData)
    {
        @Html.Partial("_" + paymentGatewayAdditionalData.Key + ".cshtml", Model)
    }

</form>